/*  eslint-disable no-undef */
var mysql = require('mysql');
var { pool } = require('./config');

const operation = (sql) => {
    // 在请求之前建立一个新的请求，防止报错Cannot enqueue Handshake after invoking quit（调用Quit后无法排队握手）
    pool = mysql.createConnection(pool.config);
    pool.connect();
    return new Promise((resolve, reject) => {
        pool.query(sql, (err, result) => {
            if (err) return err;
            resolve(result);
        });
        pool.end();
    }).then(res => {
        return res[0];
    }).catch(err => {
        return err;
    });
};

module.exports = {
    operation
};

